/**
 * 无尽模式失败界面
 */
class TaskFailUI extends UIBase{
    private btn_vedio:BaseButton;
    private btn_again:BaseButton;
    private btn_home:BaseButton;
    constructor()
    {
        super('TaskFailView');
        SoundManager.instance().playSound('fail', 1);
    }

    public init()
    {
        super.init(true);

        if(!RoleCache.instance().reviewStatus)
        {
            this.btn_home.alpha = 0;
            egret.setTimeout(()=>{
                egret.Tween.get(this.btn_home).to({
                    alpha:1
                }, 500);
            }, this, 1500);
        }
    }

    public addEvent()
    {
        this.btn_again.addTapHandler(this.playAgain, this);
        this.btn_vedio.addTapHandler(this.showVedio, this);
        this.btn_home.addTapHandler(this.backHome, this);
    }

    public playAgain()
    {   
        this.close();
        let logic:TaskCustomsUI = UIManager.instance().getLogicByName(UIConst.TASK_UI) as TaskCustomsUI;
        if(logic)
        {
            logic.rePlay();
        }
    }

    public showVedio()
    {
        if(egret.Capabilities.os == "Windows PC")
        {
            this.OneKeyToThrough();
        }
        else
        {
            //复活视频
            let self = this;
            let Success_call = function()
            {  
                self.OneKeyToThrough();
            };
            let Error_call = function()
            {  
                MessageUtil.tips('观看完整视频才能通过本关哦！');
            };
            WeChatgGameManager.instance().showVideoAd(GameConst.adList.other_vedio, Success_call, Error_call, this);
        }
    }

    //一键通关
    public OneKeyToThrough()
    {
        this.close();
        MessageUtil.tips('恭喜通关!');
        let data = {
            customs:GameManager.instance.curCustoms,
        }
        AccountPrase.instance().task_account(data);
    }

    public backHome()
    {
        let logic:TaskCustomsUI = UIManager.instance().getLogicByName(UIConst.TASK_UI) as TaskCustomsUI;
        if(logic)
        {
            logic.backHome();
        }
    }

    public close()
    {
        this.remove(1);
    }

    public removeEvent() 
    {
        this.btn_again.removeTapHandler();
        this.btn_vedio.removeTapHandler();
        this.btn_home.removeTapHandler();
    }

    public clear()
    {
        super.clear();
    }
}